<template>
    <div>
        <el-form :model="updateForm" status-icon ref="updateForm" label-width="60%" label-position="left" class="demo-updateForm">
            <el-form-item label="经销商ID" prop="tid">
                <el-input type="text" v-model="updateForm.tid" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="用户名" prop="tradername">
                <el-input type="text" v-model="updateForm.tradername" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="姓名" prop="realName">
                <el-input type="text" v-model="updateForm.realName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input type="text" v-model="updateForm.password" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="联系人" prop="linkman">
                <el-input type="text" v-model="updateForm.linkman" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="电话" prop="traderPhone">
                <el-input type="text" v-model="updateForm.traderPhone" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="邮箱" prop="traderMail">
                <el-input type="text" v-model="updateForm.traderMail" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="状态" prop="traderStatus">
                <el-radio v-model="radio" label="启用" @change="getVal">启用</el-radio>
                <el-radio v-model="radio" label="禁用" @change="getVal">禁用</el-radio>
            </el-form-item>
            <el-form-item label="备注" prop="ps">
                <el-input type="text" v-model="updateForm.ps" autocomplete="off"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm('updateForm')">提交</el-button>
                <el-button @click="resetForm('updateForm')">重置</el-button>
                <el-button @click="test()">test</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import qs from 'qs';
    export default {
        data() {
            return {
                radio:null,
                updateForm: {
                    tid:'',
                    tradername: '',
                    realName: '',
                    password: '',
                    linkman: '',
                    traderPhone: '',
                    traderMail: '',
                    traderStatus:'',
                    role: {rid:'',roleName:'',roleDetail:''},
                    ps:''
                }
            };
        },
        methods: {
            getVal(){
                this.updateForm.traderStatus=this.radio;
            },
            submitForm(formName) {
                var that=this;
                this.$refs[formName].validate((valid) => {
                    if (1) {
                        alert('提交成功');
                        console.log(that.updateForm);
                        // axios({
                        //
                        //     url: 'http://localhost:8080/ocp/updateReturnOrderById',
                        //     method: 'put',
                        //     headers: {
                        //         'Content-Type':'application/json'
                        //     },
                        //     param: qs.stringify(that.ruleForm)
                        // }).then(function (resp) {
                        //     console.log(resp);
                        // })
                        axios.post('http://localhost:8080/ocp/trader/update',that.updateForm).then(function (resp) {
                            console.log(resp);
                        })
                        this.$router.push({
                            path: '/trader',
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        },
        created() {
            var that=this;
            axios.get('http://localhost:8080/ocp/trader/findById?tid='+this.$route.query.id).then(function (resp) {
                console.log(resp);
                that.updateForm=resp.data.new_staff[0];
            });
        }
    }
</script>

<style scoped>

</style>
